package net.melon.logger;

import javax.inject.Inject;

import net.esj.basic.core.business.web.interceptor.AbstractOperatorInterceptor;
import net.melon.logger.manage.LoggerManage;
import net.melon.logger.pojo.LoggerMethod;

import com.opensymphony.xwork2.ActionInvocation;

public class LoggerInterceptor extends AbstractOperatorInterceptor {

	private LoggerManage loggerManage;
	
	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		String namespace = invocation.getProxy().getNamespace();
		String method = invocation.getProxy().getMethod();
		String className = invocation.getProxy().getActionName();
		String resultName = invocation.invoke();
		try{
			LoggerMethod loggerMethod = loggerManage.findMethod(namespace+"/"+className,method,resultName);
			loggerManage.logger(loggerMethod, invocation.getStack(), getOperator());
		}catch(NoSuchLoggerMethodException e){
		}finally{
			return resultName;
		}
	}
	
	@Inject
	public void setLoggerManage(LoggerManage loggerManage) {
		this.loggerManage = loggerManage;
	}


}
